#!usr/bin/env python  
# -*- coding:utf-8 _*-
""" 
@author:robot
@file: api02_dataflows.py 
@version:
@time: 2022/03/01 
"""
from TapClientCore.T02_tm_api.v2_api.v2_api_base import *


class Api02DataFlowsUrl(V2ApiUrlBase):
    url_dataflows = api_joint(V2ApiUrlBase().server, DATAFLOWS)
    url_dataflows_remove_all = api_joint(url_dataflows, DATAFLOWS_REMOVEALL)

    def __str__(self):
        return str({
            self.url_dataflows
        })


class Api02DataFlows(V2ApiBase):

    def get_dataflows_by_filter(self, filter):
        """
        {"where":{"name":"test"},"fields":{"name":1},"limit":1}
        {"fields":{"id":true,"name":true,"status":true,"stages":true,"stats":true,"setting":true},
        "where":{"id":{"$inq":["622b310584946174b923a227"]}}}
        :param filter:
        :return:
        """
        response = self.tapclient(
            self.get,
            Api02DataFlowsUrl().url_dataflows
            + self.access_token
            + self.filter(filter)
        )
        return response

    def post_dataflows(self, payload):
        response = self.tapclient(
            self.post,
            Api02DataFlowsUrl.url_dataflows,
            json=payload
        )
        return response

    def patch_dataflows(self, payload):
        """
        {status: "scheduled", id: "622b31c784946174b923a2c6"}
        {status: "stopping", id: "622b310584946174b923a227"}
        """
        response = self.tapclient(
            self.patch,
            Api02DataFlowsUrl.url_dataflows,
            json=payload
        )
        return response

    def post_dataflows_remove_all(self, where):
        """
        where: {"id":{"inq":["622b31c784946174b923a2c6"]}}
        :return:
        """
        response = self.tapclient(
            self.post,
            Api02DataFlowsUrl.url_dataflows_remove_all
            + self.where(where)
        )
        return response


if __name__ == '__main__':
    print(Api02DataFlowsUrl())
